package service.impl;

import service.PromotionCalculate;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 满减实现类
 */
public class FullReduction implements PromotionCalculate {
    @Override
    public BigDecimal calculate(BigDecimal price) {
        //如果金额大于100则金额减10，反之返回原金额
        price = price==null?BigDecimal.ZERO:price;
        if (price.compareTo(new BigDecimal(100)) >= 0) {
            return price.subtract(new BigDecimal(10))
                    .setScale(2, RoundingMode.HALF_UP);
        }
        return price;
    }


    @Override
    public String promotionName () {
        return "满减";
    }
}
